package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TransactionSource;
import com.ruoyi.system.service.ITransactionSourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交易来源用于标识:
	Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/system/source")
public class TransactionSourceController extends BaseController
{
    @Autowired
    private ITransactionSourceService transactionSourceService;

    /**
     * 查询交易来源用于标识:
	列表
     */
    @PreAuthorize("@ss.hasPermi('system:source:list')")
    @GetMapping("/list")
    public TableDataInfo list(TransactionSource transactionSource)
    {
        startPage();
        List<TransactionSource> list = transactionSourceService.selectTransactionSourceList(transactionSource);
        return getDataTable(list);
    }

    /**
     * 导出交易来源用于标识:
	列表
     */
    @PreAuthorize("@ss.hasPermi('system:source:export')")

    @PostMapping("/export")
    public void export(HttpServletResponse response, TransactionSource transactionSource)
    {
        List<TransactionSource> list = transactionSourceService.selectTransactionSourceList(transactionSource);
        ExcelUtil<TransactionSource> util = new ExcelUtil<TransactionSource>(TransactionSource.class);
        util.exportExcel(response, list, "交易来源用于标识: 商城订单 里程体现订单 转入转出订单 拉货订单数据");
    }

    /**
     * 获取交易来源用于标识:
	详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:source:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(transactionSourceService.selectTransactionSourceById(id));
    }

    /**
     * 新增交易来源用于标识:
	
     */
    @PreAuthorize("@ss.hasPermi('system:source:add')")

    @PostMapping
    public AjaxResult add(@RequestBody TransactionSource transactionSource)
    {
        return toAjax(transactionSourceService.insertTransactionSource(transactionSource));
    }

    /**
     * 修改交易来源用于标识:
	
     */
    @PreAuthorize("@ss.hasPermi('system:source:edit')")
    @Log(title = "交易来源用于标识: 商城订单 里程体现订单 转入转出订单 拉货订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransactionSource transactionSource)
    {
        return toAjax(transactionSourceService.updateTransactionSource(transactionSource));
    }

    /**
     * 删除交易来源用于标识:
	
     */
    @PreAuthorize("@ss.hasPermi('system:source:remove')")
    @Log(title = "交易来源用于标识: 商城订单 里程体现订单 转入转出订单 拉货订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(transactionSourceService.deleteTransactionSourceByIds(ids));
    }
}
